cmake_minimum_required(VERSION 3.5)
# 设置项目名称
project(qtdemoexecu)
# 将 src 目录下的所有源文件添加到 SOURCES 变量中

#资源预处理
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)



set(SOURCES
        main.cpp
        job/GlobleJob.cpp
        tcp/TcpClient.cpp
        timer/MyTimerExample.cpp
        serialport/HandSeriaPortData.cpp
)

set(HEAD
        include/GlobleJob.h
        include/TcpClient.h
        include/MyTimerExample.h
        include/SerialCommunication.h
        serialport/SerialCommunication.cpp
        serialport/SerialCommunication.h)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(QT_MODULES
        Core
        Gui
        Widgets
        Sql
        Network)

# 查找并链接 Qt 库
find_package(Qt5 COMPONENTS ${QT_MODULES} REQUIRED)
# 创建一个可执行文件 YourProjectExecutable
add_executable(${PROJECT_NAME} ${SOURCES} ${HEAD})
#直接将头文件添加到项目中
target_include_directories(${PROJECT_NAME} PRIVATE include/qxorm/include)
# 链接 QxOrm 库
#先添加库
add_library(QxOrm STATIC IMPORTED)
#在设置库路径
set_target_properties(QxOrm PROPERTIES IMPORTED_LOCATION ../src/lib/libQxOrm.a)
#最后链接到项目中
target_link_libraries(${PROJECT_NAME} PRIVATE QxOrm)


if(${Qt5_FOUND})
    set(Qt5_INCLUDE_DIRS "E:/qt/5.12.5/mingw73_64/include")
    include_directories(${Qt5_INCLUDE_DIRS})
    # 链接 Qt 库
    target_link_libraries(${PROJECT_NAME} PRIVATE
            Qt5::Core
            Qt5::Gui
            Qt5::Widgets
            Qt5::Sql
            Qt5::Network)
endif ()







# 复制 Qt 依赖的 DLL 到输出目录
foreach (QT_LIB ${QT_COMPONENTS})
    add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy
            "${Qt5_DIR}/bin/Qt5${QT_LIB}${DEBUG_SUFFIX}.dll"
            "$<TARGET_FILE_DIR:${PROJECT_NAME}>")
endforeach (QT_LIB)